<!-- 查看详情 -->
<template>
  <div id="dialog-container">
    <el-dialog v-dialogDrag title="数据信息" append-to-body :close-on-click-modal="false" :visible.sync="dialogVisible" @close="$emit('update:show', false)" :before-close="handleClose" :show="show" width="800px">
      <el-button type="primary" plain @click="getExcel()">导出</el-button>
      <div style="text-align: center;font-size: 15px;">
        {{currentDevice.name}}设备使用详情<br><br>{{currentDevice.fromDate}}~{{currentDevice.toDate}}
      </div>
      <hr>
      <el-table :data="tableData" border size="">
        <el-table-column prop="task_no" align="center" label="任务单号" min-width="100"></el-table-column>
        <el-table-column prop="field_name" align="center" label="检测项目"></el-table-column>
        <el-table-column prop="occupy" align="center" label="检测项目占用设备时间"></el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    getDeviceOccupyDetail
  } from "service/task";
  export default {
    data() {
      return {
        dialogVisible: false,
        tableData: []
      }
    },
    props: {
      show: {
        type: Boolean,
        default: false,
      },
      currentDevice: {
        default: {}
      }
    },
    watch: {
      show() {
        this.dialogVisible = this.show;
        debugger;
        if (this.dialogVisible) {
          getDeviceOccupyDetail({
            deviceId: this.currentDevice.deviceId,
            fromDate: this.currentDevice.fromDate,
            toDate: this.currentDevice.toDate
          }).then(res => {
            this.tableData = res.data.result.list;
          })
        }
      }
    },
    methods: {
      getExcel() {
        window.location.href= `${process.env.API_URL}` + "report/findDeviceDetailDataExcel?progressId=" + this.currentDevice.deviceId
         + "&startDate=" + this.currentDevice.fromDate + "&endDate=" + this.currentDevice.toDate+ "&auditReason="+this.currentDevice.name;
      },
      handleClose() { /* 关闭的时候更新状态值 */
        this.dialogVisible = false;
      }
    }
  }
</script>
